//
//  MHReviewViewController.m
//  MHO
//
//  Created by papo on 2/17/14.
//  Copyright (c) 2014 maihoang. All rights reserved.
//

#import "MHReviewViewController.h"
#import "Lib.h"
#import "Contants.h"
#import "News.h"
#import "MHNewsCell.h"
#import "UIImageView+WebCache.h"
#import "MHNewsDetailViewController.h"
#import "MHGameHotSlider.h"
#import "MHBaseViewController.h"

@interface MHReviewViewController ()
//@property (nonatomic, strong) MHNavibarView* navibarView;
@end

@implementation MHReviewViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
//    self.navibarView = [MHNavibarView createWithLeftButton:kFileBtnHuman rightButton:nil searchButton:YES];
//    [self.navibarView setActionSelectorDelegate:self left:nil right:nil search:nil];
//    [self.view addSubview:self.navibarView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)loadFromIndex:(int)index {
    [Lib showLoadingView];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSArray* arr = [News newsArrayFromUrl:[NSString stringWithFormat:@"http://mobile.mho.vn/services/news?Type=4&pageIndex=%d&pageSize=10&key=%@", index, kServerKey]];
        if (index == 0 || !self.data) {
            self.data = [NSMutableArray arrayWithArray:arr];
        }
        else {
            for (id news in arr) {
                [self.data addObject:news];
            }
        }
        self.currentIndex = index + 1;
        self.hotData = [News getHotNews];

        // main thread
        dispatch_async(dispatch_get_main_queue(), ^{
            [Lib removeLoadingView];
            [self stopLoading];
            [self stopLoadingMore];
            [self.tableView reloadData];
        });
    });
}

#pragma mark - UITableViewSource
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 0;
    }
    return 90;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell* cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
    if (self.hotSlider) {
        self.hotSlider.hidden = YES;
    }
    return cell;
}

@end
